<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="用户搜索：">
          <el-input v-model="listPram.keyword" placeholder="请输入昵称或手机号" clearable class="selWidth"/>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" class="table" v-loading="loading" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column
          prop="id"
          label="ID"
          width="50"
        />
        <!--<el-table-column
          label="头像" min-width="80">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image
                style="width: 36px; height: 36px"
                :src="scope.row.faceUrl"
                :preview-src-list="[scope.row.faceUrl]"
              />
            </div>
          </template>
        </el-table-column>-->
        <el-table-column
          label="昵称"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{scope.row.userName | filterEmpty  }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="手机号"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{scope.row.mobile | filterEmpty}}</span>
          </template>
        </el-table-column>
<!--        <el-table-column label="是否匿名" prop="isSecretText" min-width="120"/>-->
        <el-table-column label="提交时间" prop="createTime" min-width="120"/>
        <el-table-column label="操作" min-width="130" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" type="primary" size="mini" @click="onDetails(scope.row.id)" v-hasPermi="['admin:question:answer:info']">详情</el-button>
<!--            <el-button icon="el-icon-delete" type="danger" size="mini" @click="handlerOpenDel(scope.row)" v-hasPermi="['admin:job:require:delete']">删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <!--详情-->
    <el-dialog
      title="详情"
      :visible.sync="Visible"
      width="95vw"
      v-if="id"
      :before-close="hideEditDialog">
      <edit
        ref="jobRequireDetails"
        :id="id"
        v-if="Visible"
        @hideEditDialog="hideEditDialog"></edit>
    </el-dialog>
  </div>
</template>

<script>
import * as roleApi from '@/api/role.js'
import edit from './edit'
import { checkPermi } from "@/utils/permission";
import * as selfUtil from "@/utils/ZBKJIutil";
import * as questionApi from "@/api/questionApi.js";
import { staticTypeList } from '@/utils/constants' // 权限判断函数
export default {
  // name: "index"
  components: { edit },
  filters: {
    sexFilter(status) {
      const statusMap = {
        0: '未知',
        1: '男',
        2: '女',
        3: '保密'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      constants:this.$constants,
      loading:false,
      listData: { list: [] },
      listPram: {
        keyword: '',
        /*ipAddress: null,
        macAddress: null,
        personId: null,*/
        page: 1,
        limit: this.$constants.page.limit[0]
      },
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editData: {}
      },
      id:0,
      Visible:false,
    }
  },
  mounted() {
    this.handleGetQuestionAnswerList()
  },
  methods: {
    checkPermi,
    //控制长文本显示和收起
    showMore (row, flag) {
      this.$set(row,'show',flag)
    },

    handleSearch() {
      this.listPram.page = 1
      this.handleGetQuestionAnswerList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handleGetQuestionAnswerList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handleGetQuestionAnswerList()
    },
    /*handlerOpenDel(rowData) {
      this.$confirm('确认删除当前数据').then(() => {
        const _pram = { id: rowData.id}
        //computerApi.comDel(_pram).then(data => {
          this.$message.success('删除数据成功')
          this.handleGetQuestionAnswerList()
        //})
      })
    },*/

    handleGetQuestionAnswerList() {
      questionApi.getList( this.listPram ).then(data => {
      /*let data = {"page":1,"limit":15,"totalPage":1,"total":3,"list":[
        {"id":1,"realName":"张建东","nickname":"花开富贵","sex":1,"avatar":"https://api.java.crmeb.net/crmebimage/store/2020/08/15/adae23e354114cd5bd8f3cae740741c23opxeh8kw2.jpg","phone":"15809370822","updateTime":"2022-10-25 00:15:13","createTime":"2022-10-25 00:15:13","isSecret":0,"isSecretText":"否"},
          {"id":2,"realName":"李玉龙","nickname":"那*","sex":1,"avatar":"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKBL8QQXyP7mBDdd1sBFjd4dOWRy8lUUbDydn4zP2XPNKic4icM9ov5gP5CxKXyOXCOyDiawVHbWm9lA/132","phone":"158****0822","updateTime":"2022-10-25 00:15:13","createTime":"2022-10-25 00:15:13","isSecret":1,"isSecretText":"是"},
          {"id":4,"realName":"张原","nickname":"满天星","sex":2,"avatar":"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0NDY4UtG3Dat02JI5icxVkdYicJez6OkptOBGjicrS46l1N4Qv4P1leYbZBEojZ2uXuewgHx8BzoPHoHha9WxOLQ/132","phone":"15800360822","updateTime":"2022-10-25 00:15:13","createTime":"2022-10-25 00:15:13","isSecret":0,"isSecretText":"否"}]}*/
        this.listData = data
      })
    },

    handlerOpenEdit(editDate) {
      this.editDialogConfig.editData = editDate
      this.editDialogConfig.visible = true
    },

    // 详情
    onDetails(id){
      this.id = id
      this.Visible = true
    },
    hideEditDialog() {
      this.Visible = false
      this.handleGetQuestionAnswerList()
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.handleGetQuestionAnswerList()
    }
  }
}
</script>

<style scoped lang="scss">
  .table .showMore{
    display:block;
    width:100%;
    word-break:keep-all;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
</style>
